<?php
require 'Zend/Loader.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Table/Abstract.php';

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Bootstrap
 *
 * @author Carlos Benitez
 */


final class Bootstrap
{
private static $_config;
private static $_registro;
private static $_rootPath = null;
private $_mensajeError;
private $_msg;
private $_msgUno;


public static function main()
{
    Zend_Loader::registerAutoload();
    self::configuracionBasica();
    self::getRegistry()->set('config',self::setConfig());
    self::setLayout();
    self::setConexion();
    self::iniciarFrontController();
    

}

public static function setConexion()
{
    $config = Zend_Registry::get('config');
    try
    {
        $db = Zend_Db::factory($config->database);
        $con = $db->getConnection();
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
    }catch(Zend_Db_Statement_Exception $e){
        $this->_mensajeError =
        'Se ha producido un error interno al intentar recuperar datos.'
       .' Por favor envíe un email a sistemas@surforce.com' ;
    }catch(Zend_Db_Adapter_Exception $e){
        $this->_mensajeError =
       'Se ha producido un error al conectar a la base de datos.'
       .' Por favor reintente en unos minutos';
    }catch(Zend_Exception $e){
       $this->_mensajeError =
       'Se ha producido un error inesperado.'
       .' Por favor reintente en unos minutos';
 }
    return $db;
}

public static function configuracionBasica()
{
    error_reporting(E_ALL|E_STRICT);
    date_default_timezone_set('America/Bogota');
}

public static function setConfig()
{
    self::$_config = new Zend_Config_Ini('config.ini', 'default');
    return self::$_config;
}

public static function getRegistry()
{
   return Zend_Registry::getInstance();
}

public static function setLayout()
{
    Zend_Layout::startMvc(self::setConfig()->propertieslayout);
}
public static function iniciarFrontController()
{
   
   $frontController = Zend_Controller_Front::getInstance();
   $frontController->throwExceptions(true);
   $frontController->addModuleDirectory(self::getBaseDir() . '../application/modules');
   $frontController->dispatch();
   
   
}
public static function setBaseDir()
{
   self::$_rootPath = dirname(dirname(__FILE__));

}
public static function getBaseDir()
{
   return self::$_rootPath;
}

}

